package com.dragon.repository.mapper;

import com.dragon.repository.entity.AdminRole;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dragon.repository.entity.Role;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 用户角色表 Mapper 接口
 * </p>
 *
 * @author sy
 * @since 2023-06-12
 */
@Mapper
public interface AdminRoleMapper extends BaseMapper<AdminRole> {



    @Select("select dar.* from dragon_admin_role dar " +
            "left join dragon_admin da on dar.admin_id = da.id " +
            "where da.deleted = 0 and dar.role_id=#{roleId}")
    List<AdminRole> selectAdminByRoleId(Integer roleId);


    @Select("<script>" +
            "select dar.* from dragon_admin_role dar " +
            "left join dragon_admin da on dar.admin_id = da.id " +
            "where da.deleted = 0" +
            "<if test='roleIds.size != 0 and roleIds != \"\"'> "+
            " AND dar.role_id in " +
            "<foreach collection = 'roleIds' item = 'item' open = '(' close = ')' separator = ','>" +
            "#{item}" +
            "</foreach>" +
            "</if>" +
            "</script>")
    List<AdminRole> selectAdminByRoleIds(List<Integer> roleIds);

}
